package com.system.Exception;

import com.common.Entity.Result;
import com.common.Constant.Constants;
import io.jsonwebtoken.ExpiredJwtException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ExpiredJwtException.class)
    @ResponseBody
    public Result handleTokenExpiredException(ExpiredJwtException ex) {
        return Result.error(Constants.LOGIN_ERROR); // 返回错误码给前端
    }

    // 可以继续添加其他异常处理
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleOtherExceptions(Exception ex) {
        return Result.error("系统异常：" + ex.getMessage());
    }
}